package ystp.service;


import org.springframework.stereotype.Service;
import ystp.dao.YuecaikangjunyaowuMapper;
import ystp.model.Yuecaikangjunyaowu;
import ystp.model.YuecaikangjunyaowuExample;
import ystp.model.Yuecaikangjunyaowujieguo;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class YuecaikangjunyaowuService {

    @Resource
    YuecaikangjunyaowuMapper ddMapper;

    public boolean add (Yuecaikangjunyaowu ddYuecaikangjunyaowu){
        return ddMapper.insert(ddYuecaikangjunyaowu)==1;
    }

    public List<Map<String, Object>> findYuecaiPagingByXiangmuId(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findYuecaiPagingByXiangmuId(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public Integer getYuecaiCount(String ppXiangmuId) {
        Object mmCount = ddMapper.countYuecaiByXiangmuId(ppXiangmuId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Map<String, Object>> findYuecaiBiaojueByXiangmuId(String ppxiangmuId,String ppUserId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findYuecaiBiaojueByXiangmuId(ppxiangmuId,ppUserId,mmStartIndex,ppPageSize);
    }

    public Integer countYuecaiBiaojueByXiangmuId(String ppXiangmuId,String ppUserId) {
        Object mmCount = ddMapper.countYuecaiBiaojueByXiangmuId(ppXiangmuId,ppUserId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public boolean isExistByXiangmuId(String ppXiangmuId){
        YuecaikangjunyaowuExample mmExample = new YuecaikangjunyaowuExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppXiangmuId);
        return ddMapper.selectByExample(mmExample).size()>0;
    }

    public boolean deleteByXiangmuId(String ppXiangmuId){
        YuecaikangjunyaowuExample mmExample = new YuecaikangjunyaowuExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppXiangmuId);
        return ddMapper.deleteByExample(mmExample)>=0;
    }

    public Yuecaikangjunyaowu findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }

    public List<Yuecaikangjunyaowu> findByChuangxin(String ppChuangxin){
        YuecaikangjunyaowuExample mmExample = new YuecaikangjunyaowuExample();
        mmExample.createCriteria().andNanjingchuangxinEqualTo(ppChuangxin);
        return ddMapper.selectByExample(mmExample);
    }
}
